function* flatten(nodes = []) {
    for(let item of nodes) {
        yield item
        item.list && (yield* flatten(item.list))
    }
}

const flatList = [...flatten(treeList)]